import axios from "axios"

let baseUrl = 'http://ludir.cn:8888/api/private/v1/'

axios.defaults.baseURL = baseUrl;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';


// 请求拦截
let AUTH_TOKEN = window.localStorage.getItem('myToken') || ''

axios.interceptors.request.use(function (config) {
    // console.log('请求发送');

    if(config.url.includes('1106975712662')){
        //https://www.liulongbin.top:8888/api/private/v1/kuaidi/1106975712662
        config. baseURL='https://www.liulongbin.top:8888/api/private/v1/'
  
        config.headers['Authorization']='Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjUwMCwicmlkIjowLCJpYXQiOjE2Mzg5MjU4MDUsImV4cCI6MTYzOTAxMjIwNX0.R2S3WJp6i1DStWIKuDh8ffpEAbpOlNPt_DvJ-49MHZo'
      }else {
        config. baseURL=baseUrl
        config.headers['Authorization'] = AUTH_TOKEN; // 在发送请求之前在请求头配置token 
      }
    // config.headers['Authorization'] = AUTH_TOKEN;
    return config
}, function(error) {
    return Promise.reject(error)
})

//  响应拦截
axios.interceptors.response.use(function(response) {
    // console.log(response);
    return response.data
}, function(error) {
    console.log(error);
    return Promise.reject(error)
})



// 登录请求API的封装
export let getLogin = (params) => axios.post('login', params)

// 获取users列表数据请求
export let getUsers = (params) => axios.get('users', {params})

// 更改用户状态
export let getChangeUserState = ({ id, type }) => axios.put( `users/${id}/state/${type}` )

// 添加用户
export let getAddUsers = (params) => axios.post('users', params)

// 删除用户
export let getDeleteUsers = (params) => axios.delete(`users/${params}`)

// 修改用户信息
export let getUpdateUsers = (params) => axios.put(`users/${params.id}`, params)

// 获取角色列表
export let getRoles = ( params={} ) => axios.get('roles', { params })

// 分配角色请求users/:id/role
export let getUsersRole = ( params ) => axios.put(`users/${params.id}/role`, params) 

// 添加角色
export let getAddRoles = (params) => axios.post('roles', params)

// 获取左侧分类列表
export let getMenuList = (params={}) => axios.get('menus')

// 获取权限列表
export let getRights = (params) => axios.get(`rights/${params.type}`)

// 修改角色列表
export let getUpdateRoles = (params) => axios.put(`roles/${params.id}`, params)

// 删除角色
export let getDeleteRole = (params) => axios.delete(`roles/${params}`)

// 删除角色指定权限
export let getDeleteRolesRights = ( {roleId, rightId} ) => axios.delete(`roles/${roleId}/rights/${rightId}`)

// 角色授权
export let getRolesRights = ({roleId, rids}) => axios.post(`roles/${roleId}/rights`, {rids})

// 数据可视化展示
export let getCharts = (params) => axios.get(`reports/type/1`)

// 获取商品列表
export let getGoods = (params) => axios.get('goods',{params})

// 删除商品
export let getDeleteGoods = (params) => axios.delete(`goods/${params}`)

// 编辑商品
export let getEditGoods = (params) => axios.put(`goods/${params.goods_id}`, params)

// 获取分类列表
export let getCategories = (params) => axios.get('categories',{params})

// 获取订单列表
export let getOrders = (params) => axios.get('orders', {params})

// 获取物流信息
export let getPackageInformation = (params) => axios.get(`/kuaidi/${params.id}`)
